46
Beginner’s Guide to Code Algorithms
46
STEP 9
The principle here is to compare the cell with each of the nine numbers, one grid
at a time. If the number is found in cantbelist for a cell, or the cell is occupied by
a number that is not the same as the number being searched, then a count is kept
to see how many cells are there of this kind in that row. If there are 3, then it is a
candidate, less than 3 does not qualify hence count is reset to zero for that grid. If
the count is 6 for that row, this means there are two out of the three adjacent grids
that cannot have this number. Hence the third grid included in this row must have
this number. Therefore, the other rows in this third grid cannot have this number—
these are then added to the cantbelist.
For putnumber = 1 to 9
:
:
‘ *** algorithm to refine cantbelist based on one row of 3 by 3 grid
For i = 1 To 9
middlerowcount(i) = 0
Next i
For i = 1 To 9 Step 3
For j = 1 To 9 Step 3
For k = 1 To 3
n = Int((i - 1) / 3) * 3 + k
triocount = 0
For l = 1 To 3
p = Int((j - 1) / 3) * 3 + l
If (sbox(n, p) <> putnumber And sbox(n, p) <> ““) Or
findincantbelist(putnumber, n, p) = 1 Then
middlerowcount(n) = middlerowcount(n) + 1
triocount = triocount + 1
End If
Next l
If triocount < 3 Then
middlerowcount(n) = middlerowcount(n) - triocount
savedcolumn(n) = p
End If
Next k
Next j
Next i
For i = 1 To 9
If middlerowcount(i) = 6 Then
a = i Mod 3
If a = 0 Then
savedrow1 = i - 2
savedrow2 = i - 1
Else
If a = 1 Then
savedrow1 = i + 1
savedrow2 = i + 2
Else